import * as mongoose from "mongoose";
const Schema = mongoose.Schema;

export const CategorySchema = new Schema({
  name: { // 分类的名称
    type: String,
    required: true,
  },
  imageUrl: {
    type: String
  },
  // parent字段指向是父类
  parent: {
    type: Schema.Types.ObjectId,
    ref: 'Category'
  },
  order: {
    type: Number,
    default: 100
  },
  isActive: {
    type: Boolean
  }
}, {
  timestamp: true,
  toJSON: {
    virtuals: true,
    transform(doc, ret) {
      ret.id = ret._id
      delete ret._id
      delete ret.__v
    }
  }
})